﻿/************************************************
* Copyright (C) 2011 东北农业大学(NEAU) 版权所有。
* 文件名：
* 版本号：
* 文件功能描述：
* 作者：
* 创建日期:
* 版本号：
* 修改人：
* 修改日期：
* 修改描述：
************************************************/
Ext.BLANK_IMAGE_URL = '/script/ext/resources/images/s.gif';
//创建根节点
var treeRoot = new Ext.tree.AsyncTreeNode({
    text: '功能菜单',
    id: 'treeRoot',
    expanded: true,
    leaf: false
});
//创建树面板
var treeMenu = new Ext.tree.TreePanel({
    loader: new Ext.tree.TreeLoader({ dataUrl: "/Module/Default/SERVER/module/MenuTree.aspx" }),
    id: 'treeMenu',
    region: 'west',
    split: true,
    width: 160,
    minSize: 150,
    maxSize: 500,
    collapsible: true,
    margins: '0 0 5 5',
    cmargins: '0 5 5 5',
    rootVisible: false,
    lines: true,
    autoScroll: true,
    animCollapse: true,
    animate: true,
    title: "网络课程管理系统 2012",
    bodyStyle: "padding: 5px;",
    tbar: ['系统管理功能菜单', '->', {
        iconCls: 'icon-expand-all',
        tooltip: '展开全部',
        handler: function () { treeRoot.expand(true); }
    }, {
        iconCls: 'icon-collapse-all',
        tooltip: '折叠全部',
        handler: function () { treeRoot.collapse(true); }
    }]
});
treeMenu.setRootNode(treeRoot);

//定义标签文档主面板
DocPanel = Ext.extend(Ext.Panel, {
    closable: true,
    autoScroll: true,
    initComponent: function () {
        this.title = treeMenu.getNodeById(this.cclass).attributes.text;
        Ext.apply(this, {});
        DocPanel.superclass.initComponent.call(this);
    }
});

//定义主面板
MainPanel = function () {
    MainPanel.superclass.constructor.call(this, {
        id: 'doc-body',
        region: 'center',
        margins: '0 5 5 0',
        resizeTabs: true,
        minTabWidth: 135,
        tabWidth: 135,
        plugins: new Ext.ux.TabCloseMenu(),
        enableTabScroll: true,
        activeTab: 0,
        items: {
            id: 'welcome-panel',
            title: '系统首页',
            autoLoad: { url: 'welcome.aspx', callback: this.initSearch, scope: this },
            iconCls: 'icon-house-16',
            autoScroll: true,
            bbar: ['技术支持:东北农业大学继续教育中心', {
                xtype: "tbfill"
            }, {
                pressed: false,
                text: '技术支持',
                handler: function () {
                    Ext.Msg.alert("关于", "东北农业大学继续教育中心");
                }
            }]
        }
    });
};
//向主面板添加事件
Ext.extend(MainPanel, Ext.TabPanel, {
    animate: true,
    initEvents: function () {
        MainPanel.superclass.initEvents.call(this);
    },
    loadClass: function (href, cls, member) {
        var id = 'docs-' + cls;
        var tab = this.getComponent(id);
        if (tab) {
            this.setActiveTab(tab);
            if (member) {
                tab.scrollToMember(member);
            }
        }
        else {
            var p = this.add(new DocPanel({
                id: id,
                cclass: cls,
                html: "<iframe id='iframe-main' frameborder=\"0\" src=\"" + href + "\" width=\"100%\" height=\"100%\"></iframe>",
                iconCls: treeMenu.getNodeById(cls).attributes.iconCls
            }));
            this.setActiveTab(p);
        }
    }
});
//实例化主面板
var mainPanel = new MainPanel();
//为树创建单击事件
treeMenu.on('click', function (node, e) {
    if (node.isLeaf() && node.attributes.href != "#") {
        e.stopEvent();
        var arry = new Array();
        arry = node.id.split(".");
        mainPanel.loadClass(node.attributes.href + "?modelid=" + arry[1], node.id);
    }
});
//元素加载后运行
Ext.onReady(function () {
    Ext.QuickTips.init();
    //创建布局
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [{
            cls: 'docs-header',
            height: 50,
            region: 'north',
            xtype: 'box',
            el: 'header',
            margins: '0'
        }, {
            height: 20,
            region: 'south',
            xtype: 'box',
            html: "<div style='text-align:center;'>版权所有 © 2011 NetSoft</div>",
            margins: '5'
        }, treeMenu, mainPanel]
    });
    viewport.doLayout();

    new ButtonPanel('', [{
        tooltip: '系统首页',
        iconCls: 'home',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            mainPanel.setActiveTab(0);
        }
    }, {
        tooltip: '时钟',
        iconCls: 'clock32',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            Ext.Msg.alert("当前时间", new Date().toDateString());
        }
    }, {
        tooltip: '日程安排',
        iconCls: 'calendar',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            Ext.Msg.alert("当前时间", new Date().toDateString());
        }
    }, {
        tooltip: '文件柜',
        iconCls: 'library',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            Ext.Msg.alert("当前时间", new Date().toDateString());
        }
    }, {
        tooltip: '通讯录',
        iconCls: 'book',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            Ext.Msg.alert("当前时间", new Date().toDateString());
        }
    }, {
        tooltip: '屏幕锁',
        iconCls: 'lock',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            Ext.Msg.alert("当前时间", new Date().toDateString());
        }
    }, {
        tooltip: '帮助文档',
        iconCls: 'help',
        scale: 'large',
        iconAlign: 'top',
        handler: function () {
            Ext.Msg.alert("当前时间", new Date().toDateString());
        }
    }]);

    //延时加载事件
    setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 250);
});

ButtonPanel = Ext.extend(Ext.Panel, {
    layout: 'table',
    defaultType: 'button',
    baseCls: 'x-plain',
    cls: 'btn-panel',
    renderTo: 'buttonsDiv',
    menu: undefined,
    split: false,
    layoutConfig: {
        columns: 20
    },
    constructor: function (desc, buttons) {
        for (var i = 0, b; b = buttons[i]; i++) {
            b.menu = this.menu;
            b.enableToggle = this.enableToggle;
            b.split = this.split;
            b.arrowAlign = this.arrowAlign;
        }
        var items = [{
            xtype: 'box',
            autoEl: { tag: 'h3', html: desc, style: "padding:10px;" },
            colspan: 3
        }].concat(buttons);
        ButtonPanel.superclass.constructor.call(this, {
            items: items
        });
    }
});